using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OleDb;
namespace QLNS.Data
{
    public class NhanVien_db
    {
        Services m_Ds = new Services();
        public NhanVien_db() { }

        public DataTable DanhSachNhanVien()
        {
            //OleDbCommand cmd = new OleDbCommand("SELECT NV.ID AS ID,NV.Ho,NV.TenLot,NV.Ten,PB.Name as Name_PB,CV.Name as Name_CV FROM NHANVIEN NV, PHONGBAN PB,CHUCVU CV where NV.PhongBan=PB.ID and NV.ChucVu=CV.ID");
            OleDbCommand cmd = new OleDbCommand("SELECT NV.ID AS ID,NV.Ho,NV.TenLot,NV.Ten,NV.PhongBan,NV.ChucVu FROM NHANVIEN NV, PHONGBAN PB,CHUCVU CV where NV.PhongBan=PB.ID and NV.ChucVu=CV.ID");
            m_Ds.Load(cmd);

            return m_Ds;
        }
        public bool LuuNhanVien(string manhanvien, string ho, string tenlot, string ten, string phongban, string chucvu)
        {
            OleDbCommand cmd = new OleDbCommand("insert into NHANVIEN values(" + manhanvien + "," + ho + "," + tenlot + "," + ten + "," + phongban + "," + chucvu + ") ");
            
            return m_Ds.ExecuteNoneQuery(cmd)>0;
            
        }
        public DataRow NewRow()
        {
            return m_Ds.NewRow();
        }

        public void Add(DataRow row)
        {
            m_Ds.Rows.Add(row);
        }

        public bool Save()
        {
            return m_Ds.ExecuteNoneQuery() > 0;
        }
        public DataTable TimTheoTen(string ten)
        {
            string sql = "SELECT * FROM NHANVIEN where Ten like '%" + ten + "%'";
            OleDbCommand cmd = new OleDbCommand(sql);
            m_Ds.Load(cmd);

            return m_Ds;
        }

        public DataTable TimTheoMa(string id)
        {
            string sql = "SELECT * FROM NHANVIEN where ID like '%" + id + "%'";
            OleDbCommand cmd = new OleDbCommand(sql);
            m_Ds.Load(cmd);

            return m_Ds;
        }

    }
}
